<!-- 表单管理 -->
<template>
	<div class="t-wp" v-loading="state.loading">
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
			<el-form class="text-right" :model="state.queryParams" ref="queryForm" :inline="true">
				<!-- <el-form-item label="模板名称">
					<el-input v-model="state.queryParams.aaa" placeholder="请输入"/>
				</el-form-item>
				<el-form-item>
					<el-button-group>
						<el-button type="primary" icon="ele-Search" @click="handleQuery"> 查询 </el-button>
						<el-button icon="ele-Refresh" @click="resetQuery"> 重置 </el-button>
					</el-button-group>
				</el-form-item> -->
				<el-form-item>
					<el-button type="primary" icon="ele-Plus" @click="showAdd()"> 新增 </el-button>
				</el-form-item>
			</el-form>
		</el-card>
		<el-card class="full-table" shadow="hover" style="margin-top: 8px">
			<el-table :data="state.list" style="width: 100%" border>
				<el-table-column type="index" label="序号" width="55" align="center" />
				<el-table-column prop="formName" label="模板名称" show-overflow-tooltip />
				<!-- <el-table-column prop="aa3" label="启用状态" width="200" align="center">
					<template #default="scope">
						<el-switch v-model="scope.row.aa3" />
					</template>
				</el-table-column> -->
				<el-table-column label="操作" width="300" align="center" fixed="right" show-overflow-tooltip>
					<template #default="scope">
						<el-button icon="el-icon-edit" size="small" text type="primary" @click="showAdd(scope.row)">编辑模板</el-button>
						<el-button icon="el-icon-edit" size="small" text type="primary" @click="toEditForm(scope.row)">编辑内容</el-button>
						<el-button icon="el-icon-delete" size="small" text type="primary" @click="deleteRow(scope.row)">删除模板</el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-card>

		<addModal ref="addModalRef" @reload="handleQuery"></addModal>
	</div>
</template>

<script setup name="SupplierManage">
import { onMounted, reactive, ref } from 'vue';
import {useRouter, useRoute} from "vue-router";
import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
import addModal from "./modules/addModal.vue";
import {$get, $post, $postparams} from '/@/utils/request';

const router = useRouter();
const route = useRoute();
const addModalRef = ref();

const PUBLIC_PATH = import.meta.env.VITE_PUBLIC_PATH;
const state = reactive({
	loading: false,
	queryParams: {
		aaa: '',
		bbb: '',
	},

	list: [],

	test: ''
});

onMounted(async () => {
	handleQuery();
});

// 查询操作
const handleQuery = async () => {
	state.loading = true;
	let params = {
		input: 0,
		// ...state.queryParams
	}
	var res = await $get('/projectTemplateModule/getformtemplate', params);
	state.list = res.result || [];
	state.loading = false;
};

// 重置操作
const resetQuery = () => {
	state.queryParams.aaa = '';
	state.queryParams.bbb = '';
	handleQuery();
};

// 显示添加
const showAdd = (row) => {
	addModalRef.value.open(row);
}

// 删除行
const deleteRow = row => {
	ElMessageBox.confirm('此操作将删除该模板，是否继续？', '提示', {
		type: 'warning'
	}).then(async () => {
		let params = {
			input: row.id
		}
		var res = await $postparams('/projectTemplateModule/removeformtemplate', params);
		ElNotification({
	    title: '提示',
	    message: '删除成功',
	    type: 'success',
	  })
	  // 更新列表
	  handleQuery();
	})
}

// 显示编辑表单
const toEditForm = row => {
	localStorage.setItem('template_id', row.id);
	router.push({
		path: '/template/pdf/edit',
		query: {
			tabTitle: '模板-'+row.formName
		}
	})
	return;
	if(row.description == 'EXCEL') {
		router.push({
			path: '/template/excel/edit',
			query: {
				id: row.id
			}
		})
	} else if (row.description == 'WORD') {
		router.push({
			path: '/template/word/edit'
		})
	}
}

</script>

<style lang="scss" scoped>
.t-wp {
	
}
</style>
